package com.github.jinatonic.confetti.sample.slice;

import com.github.jinatonic.confetti.CommonConfetti;
import com.github.jinatonic.confetti.ConfettiManager;
import com.github.jinatonic.confetti.ConfettiSource;
import com.github.jinatonic.confetti.sample.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.components.AttrHelper;
import ohos.global.resource.NotExistException;
import ohos.global.resource.ResourceManager;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;

public class FallingConfettiFromPointAbilitySlice extends AbstractAbilitySlice{

    @Override
    protected ConfettiManager generateOnce() {
        return getCommonConfetti().oneShot();
    }

    @Override
    protected ConfettiManager generateStream() {
        return getCommonConfetti().stream(3000);
    }

    @Override
    protected ConfettiManager generateInfinite() {
        return getCommonConfetti().infinite();
    }

    private CommonConfetti getCommonConfetti() {
        final int size = AttrHelper.vp2px(6,getContext());
        final ConfettiSource confettiSource = new ConfettiSource(-size, -size);
        final CommonConfetti commonConfetti =
                CommonConfetti.rainingConfetti(container, confettiSource, getColors());

        final int velocitySlow = AttrHelper.vp2px(50,getContext());
        final int velocityNormal = AttrHelper.vp2px(100,getContext());
        final int velocityFast = AttrHelper.vp2px(200,getContext());

        // Further configure it
        commonConfetti.getConfettiManager()
                .setVelocityX(velocityFast, velocityNormal)
                .setAccelerationX(-velocityNormal, velocitySlow)
                .setTargetVelocityX(0, velocitySlow / 2f)
                .setVelocityY(velocityNormal, velocitySlow);

        return commonConfetti;
    }
}
